/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecommerce.dao;

import ecommerce.model.Wishlist;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Hadi
 */
@Repository
public class WishlistDao {
    @Autowired private SessionFactory sessionFactory;

    public void save(Wishlist w){
        sessionFactory.getCurrentSession().saveOrUpdate(w);
    }

    public void delete(Wishlist w){
        sessionFactory.getCurrentSession().delete(w);
    }

    public Wishlist findById(Long id){
        return (Wishlist) sessionFactory.getCurrentSession().get(Wishlist.class, id);
    }

    public List<Wishlist> getAll(){
        return sessionFactory.getCurrentSession().createQuery("from Wishlist").list();
    }

}
